home *** CD-ROM | disk | FTP | other *** search
- package com.ibm.xml.xpointer;
-
- import com.ibm.xml.parser.XMLChar;
- import java.util.Hashtable;
- import java.util.Vector;
-
- public class XPointerParser {
- static Hashtable s_keys = new Hashtable(14);
- String xpointer;
- int index;
-
- public XPointer parse(String var1) throws XPointerParseException {
- return this.parse(var1, 0);
- }
-
- public XPointer parse(String var1, int var2) throws XPointerParseException {
- AbsTerm var3 = null;
- Vector var4 = new Vector();
- this.xpointer = var1;
- this.index = var2;
- byte var5 = 0;
- boolean var6 = false;
-
- while(this.index < this.xpointer.length() && !var6) {
- switch (var5) {
- case 0:
- String var14 = this.getName();
- if (var14 == null) {
- throw new XPointerParseException("Syntax error: [ROOT] Expect a name.");
- }
-
- Integer var15 = (Integer)s_keys.get(var14);
- if (var15 == null) {
- String var17 = "Syntax error: [ROOT] Unexpected name: " + var14;
- throw new XPointerParseException(var17);
- }
-
- switch (var15) {
- case 1:
- case 2:
- case 3:
- case 4:
- var3 = this.parseAbsTerm(var15);
- break;
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:
- case 14:
- var4.addElement(this.parseOtherTerm(var15, var14));
- break;
- default:
- var6 = true;
- throw new XPointerParseException("Internal Error: [ROOT]");
- }
-
- var5 = 1;
- break;
- case 1:
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 46) {
- var6 = true;
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) == 40) {
- var4.addElement(this.parseOtherTerm(-1, (String)null));
- } else {
- String var7 = this.getName();
- if (var7 == null) {
- throw new XPointerParseException("Syntax error: [ROOT] Expect a name.");
- }
-
- Integer var8 = (Integer)s_keys.get(var7);
- if (var8 == null) {
- String var16 = "Syntax error: [ROOT] Unexpected name: " + var7;
- throw new XPointerParseException(var16);
- }
-
- switch (var8) {
- case 1:
- case 2:
- case 3:
- case 4:
- var6 = true;
- String var9 = "Syntax error: [ROOT] Unexpected name: " + var7;
- throw new XPointerParseException(var9);
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:
- case 14:
- var4.addElement(this.parseOtherTerm(var8, var7));
- break;
- default:
- var6 = true;
- throw new XPointerParseException("Internal Error: [ROOT]");
- }
- }
- }
- break;
- default:
- var6 = true;
- String var18 = "Internal Error: [ROOT] Invalid state: " + var5;
- throw new XPointerParseException(var18);
- }
- }
-
- this.xpointer = this.xpointer.substring(var2, this.index);
- return new XPointer(var3, var4);
- }
-
- public String toString() {
- return this.xpointer;
- }
-
- public static void main(String[] var0) {
- if (var0.length != 1) {
- System.err.println("Require 1 argument.");
- System.exit(1);
- }
-
- try {
- XPointer var1 = (new XPointerParser()).parse(var0[0]);
- System.out.println("PARSED and RESTRUCTED: " + var1.toString());
- } catch (XPointerParseException var2) {
- ((Throwable)var2).printStackTrace();
- }
- }
-
- AbsTerm parseAbsTerm(int var1) throws XPointerParseException {
- String var2 = null;
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 40) {
- String var5 = "Syntax error: expect `(': " + this.left();
- throw new XPointerParseException(var5);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- if (var1 == 3) {
- String var3 = this.getName();
- if (var3 == null) {
- String var4 = "Syntax error: expect ID name: " + this.left();
- throw new XPointerParseException(var4);
- }
-
- var2 = var3;
- } else if (var1 == 4) {
- var2 = this.getSkipLit();
- }
-
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 41) {
- throw new XPointerParseException("Syntax error: expect `)'");
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- return new AbsTerm(var1, var2);
- }
- }
- }
-
- RelTerm parseRelTerm(int var1) throws XPointerParseException {
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 40) {
- String var9 = "Syntax error: expect `(': " + this.left();
- throw new XPointerParseException(var9);
- } else {
- boolean var2 = false;
- int var3 = -1;
- String var4 = null;
- byte var5 = 0;
- Vector var6 = new Vector();
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- String var7 = this.getName();
- if (var7 != null && "all".equals(var7)) {
- var2 = true;
- } else {
- if (var7 != null) {
- String var8 = "Syntax error: [relterm] expect a name or number: " + var7;
- throw new XPointerParseException(var8);
- }
-
- var3 = this.getDigit();
- }
-
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) == 44) {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) == 35) {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- var7 = this.getName();
- if (var7 != null) {
- if (var7.equals("element")) {
- var5 = 2;
- } else if (var7.equals("pi")) {
- var5 = 3;
- } else if (var7.equals("comment")) {
- var5 = 4;
- } else if (var7.equals("text")) {
- var5 = 5;
- } else if (var7.equals("cdata")) {
- var5 = 6;
- } else if (var7.equals("all")) {
- var5 = 7;
- }
- }
- } else {
- var4 = this.getName();
- var5 = 1;
- }
-
- if (var5 == 0) {
- String var11 = "Syntax error: [relterm] expect a name/#element/#pi/#comment/#text/#cdata/#all: #" + var7;
- throw new XPointerParseException(var11);
- }
-
- while(this.index < this.xpointer.length() && (this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 41 && (this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) == 44) {
- var6.addElement(this.parseAttribute());
- }
- }
-
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 41) {
- String var10 = "Syntax error: [relterm] expect `)': " + this.left();
- throw new XPointerParseException(var10);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- return new RelTerm(var1, var2, var3, var5, var4, var6);
- }
- }
- }
-
- RelTermAttribute parseAttribute() throws XPointerParseException {
- byte var2 = -1;
- Object var3 = null;
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- String var1;
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) == 42) {
- var1 = "*";
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
- } else {
- var1 = this.getName();
- if (var1 == null) {
- String var10 = "Syntax error: expect `*' or Name: " + this.left();
- throw new XPointerParseException(var10);
- }
- }
-
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 44) {
- String var9 = "Syntax error: expect `,': " + this.left();
- throw new XPointerParseException(var9);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- String var7;
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) == 42) {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- var2 = 1;
- var7 = "*";
- } else if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) == 35) {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- String var4 = this.getName();
- if (var4 == null || !"IMPLIED".equals(var4)) {
- String var5 = "Syntax error: [relterm] expect `#IMPLIED': " + this.left();
- throw new XPointerParseException(var5);
- }
-
- var2 = 0;
- var7 = "#IMPLIED";
- } else if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 34 && (this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 39) {
- var2 = 2;
- var7 = this.getName();
- if (var7 == null) {
- String var8 = "Syntax error: [relterm] expect a name: " + this.left();
- throw new XPointerParseException(var8);
- }
- } else {
- var2 = 3;
- var7 = this.getSkipLit();
- }
-
- return new RelTermAttribute(var1, var2, var7);
- }
- }
-
- StringTerm parseStringTerm() throws XPointerParseException {
- boolean var1 = false;
- int var2 = -1;
- Object var3 = null;
- boolean var4 = false;
- boolean var5 = false;
- int var6 = -1;
- int var7 = -1;
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 40) {
- String var12 = "Syntax error: [string] expect `(': " + this.left();
- throw new XPointerParseException(var12);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- String var8 = this.getName();
- if (var8.equals("all")) {
- var1 = true;
- } else {
- var2 = this.getDigit();
- }
-
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 44) {
- String var13 = "Syntax error: [string] expect `,':" + this.left();
- throw new XPointerParseException(var13);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- String var10 = this.getSkipLit();
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) == 44) {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- var4 = true;
- var8 = this.getName();
- if (var8.equals("end")) {
- var5 = true;
- } else {
- var6 = this.getDigit();
- }
-
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) == 44) {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- var7 = this.getNaturalNumber();
- }
- }
-
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 41) {
- String var9 = "Syntax error: [string] expect `)':" + this.left();
- throw new XPointerParseException(var9);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- return new StringTerm(var1, var2, var10, var4, var5, var6, var7);
- }
- }
- }
- }
-
- AttrTerm parseAttrTerm() throws XPointerParseException {
- Object var1 = null;
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 40) {
- String var5 = "Syntax error: [attr] expect `(': " + this.left();
- throw new XPointerParseException(var5);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- String var3 = this.getName();
- if (var3 == null) {
- String var4 = "Syntax error: [attr] expect a name: " + this.left();
- throw new XPointerParseException(var4);
- } else if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 41) {
- String var2 = "Syntax error: [attr] expect `)': " + this.left();
- throw new XPointerParseException(var2);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- return new AttrTerm(var3);
- }
- }
- }
-
- SpanTerm parseSpanTerm() throws XPointerParseException {
- Object var1 = null;
- Object var2 = null;
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 40) {
- String var7 = "Syntax error: [span] expect `(': " + this.left();
- throw new XPointerParseException(var7);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- XPointerParser var3 = new XPointerParser();
- XPointer var5 = var3.parse(this.xpointer, this.index);
- this.index += var3.xpointer.length();
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 44) {
- String var8 = "Syntax error: [span] expect ',': " + this.left();
- throw new XPointerParseException(var8);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- XPointer var6 = var3.parse(this.xpointer, this.index);
- this.index += var3.xpointer.length();
- if ((this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1) != 41) {
- String var4 = "Syntax error: [span] expect ')': " + this.left();
- throw new XPointerParseException(var4);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- return new SpanTerm(var5, var6);
- }
- }
- }
- }
-
- static String makeSkipLit(String var0) {
- return var0.indexOf(34) >= 0 ? "'" + var0 + "'" : "\"" + var0 + "\"";
- }
-
- String left() {
- return this.xpointer.substring(this.index);
- }
-
- private OtherTerm parseOtherTerm(int var1, String var2) throws XPointerParseException {
- Object var3 = null;
- switch (var1) {
- case -1:
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- var3 = this.parseRelTerm(var1);
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- default:
- break;
- case 12:
- var3 = this.parseSpanTerm();
- break;
- case 13:
- var3 = this.parseAttrTerm();
- break;
- case 14:
- var3 = this.parseStringTerm();
- }
-
- return (OtherTerm)var3;
- }
-
- // $FF: renamed from: in () boolean
- private final boolean method_0() {
- return this.index < this.xpointer.length();
- }
-
- private final int next() {
- return this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1;
- }
-
- private final int get() {
- return this.index < this.xpointer.length() ? this.xpointer.charAt(this.index++) : -1;
- }
-
- private void error(String var1) throws XPointerParseException {
- throw new XPointerParseException(var1);
- }
-
- private String getName() {
- int var1 = this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1;
- if (!XMLChar.isLetter((char)var1) && var1 != 95 && var1 != 58) {
- return null;
- } else {
- StringBuffer var2 = new StringBuffer(32);
-
- do {
- var2.append((char)(this.index < this.xpointer.length() ? this.xpointer.charAt(this.index++) : -1));
- } while(this.index < this.xpointer.length() && XMLChar.isNameChar((char)(this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1)));
-
- return var2.toString();
- }
- }
-
- private String getSkipLit() throws XPointerParseException {
- StringBuffer var1 = new StringBuffer(32);
- int var2 = this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1;
- if (var2 != 34 && var2 != 39) {
- String var3 = "Syntax error: expect \" or ': " + this.left();
- throw new XPointerParseException(var3);
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- while(this.index < this.xpointer.length() && var2 != (this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1)) {
- var1.append((char)(this.index < this.xpointer.length() ? this.xpointer.charAt(this.index++) : -1));
- }
-
- if (this.index >= this.xpointer.length()) {
- throw new XPointerParseException("Unexpected end.");
- } else {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- return var1.toString();
- }
- }
- }
-
- private int getDigit() throws XPointerParseException {
- int var1 = this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1;
- byte var2 = 1;
- if (var1 == 45) {
- var2 = -1;
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
- } else if (var1 == 43) {
- var2 = 1;
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
- }
-
- int var3 = 0;
- if (this.index < this.xpointer.length()) {
- int var10000 = this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1;
- var1 = var10000;
- if (Character.isDigit((char)var10000)) {
- if (this.index < this.xpointer.length()) {
- this.xpointer.charAt(this.index++);
- }
-
- for(var3 = Character.getNumericValue((char)var1); this.index < this.xpointer.length() && Character.isDigit((char)(this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1)); var3 = var3 * 10 + Character.getNumericValue((char)(this.index < this.xpointer.length() ? this.xpointer.charAt(this.index++) : -1))) {
- }
-
- return var3 * var2;
- }
- }
-
- String var4 = "Syntax error: expect digits: " + this.left();
- throw new XPointerParseException(var4);
- }
-
- private int getNaturalNumber() throws XPointerParseException {
- int var1 = 0;
- if (this.index < this.xpointer.length() && Character.isDigit((char)(this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1))) {
- for(var1 = Character.getNumericValue((char)(this.index < this.xpointer.length() ? this.xpointer.charAt(this.index++) : -1)); this.index < this.xpointer.length() && Character.isDigit((char)(this.index < this.xpointer.length() ? this.xpointer.charAt(this.index) : -1)); var1 = var1 * 10 + Character.getNumericValue((char)(this.index < this.xpointer.length() ? this.xpointer.charAt(this.index++) : -1))) {
- }
-
- return var1;
- } else {
- String var2 = "Syntax error: expect digits: " + this.left();
- throw new XPointerParseException(var2);
- }
- }
-
- static {
- s_keys.put(XPointer.literals[1], new Integer(1));
- s_keys.put(XPointer.literals[2], new Integer(2));
- s_keys.put(XPointer.literals[3], new Integer(3));
- s_keys.put(XPointer.literals[4], new Integer(4));
- s_keys.put(XPointer.literals[5], new Integer(5));
- s_keys.put(XPointer.literals[6], new Integer(6));
- s_keys.put(XPointer.literals[7], new Integer(7));
- s_keys.put(XPointer.literals[8], new Integer(8));
- s_keys.put(XPointer.literals[9], new Integer(9));
- s_keys.put(XPointer.literals[10], new Integer(10));
- s_keys.put(XPointer.literals[11], new Integer(11));
- s_keys.put(XPointer.literals[12], new Integer(12));
- s_keys.put(XPointer.literals[13], new Integer(13));
- s_keys.put(XPointer.literals[14], new Integer(14));
- }
- }
-